package com.lzhpo.core.aop;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;
import java.util.Arrays;

/**
 * @ClassName LoggerAspect
 * @Description: TODO
 * @Author lijin
 * @Date 2020/7/23
 * @Author 740393778@qq.com
 * @Version V1.0
 **/
@Slf4j
@Aspect
@Component
@Lazy(false)
public class LoggerAspect {

    @Pointcut("@annotation(org.springframework.web.bind.annotation.GetMapping)")
    private void getMethod() {
    }

    @Pointcut("@annotation(org.springframework.web.bind.annotation.PostMapping)")
    private void postMethod() {
    }

    /*@Before("getMethod() || postMethod()") //在切入点的方法run之前要干的
    public void logBeforeController(JoinPoint joinPoint) {
        RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();//这个RequestContextHolder是Springmvc提供来获得请求的东西
        HttpServletRequest request = ((ServletRequestAttributes)requestAttributes).getRequest();
        log.info("#url : " + request.getRequestURL().toString());
        log.info("#the args of this method : " + Arrays.toString(joinPoint.getArgs()));
    }*/

}
